package com.dong.es.entity.searchparam.page;

import co.elastic.clients.elasticsearch.core.SearchRequest;
import com.dong.es.entity.EsBaseDTO;

import java.util.List;

/**
 * @description: Es SearchAfter 分页参数
 * @author: 陈瑞东
 * @create: 2022-07-11 10:00
 */
public class EsSearchAfterPageParam extends EsPageParam {
    private static final long serialVersionUID = 2442334468197064098L;

    // 数据条数
    private Integer size;
    // 排序列表，上次查询的最后一个数据的排序值
    private List<String> searchAfter;

    public EsSearchAfterPageParam(Integer size, List<String> searchAfter) {
        this.size = size;
        this.searchAfter = searchAfter;
    }

    @Override
    protected boolean valid(EsBaseDTO esBaseDTO) {
        return size != null;
    }

    @Override
    public void loadTo(SearchRequest.Builder target) {
        target.size(size);
        if (searchAfter != null && !searchAfter.isEmpty()) {
            target.searchAfter(searchAfter);
        }
    }
}
